package com.fan.admin.service.impl;

import com.fan.admin.dao.StudentScoresMapper;
import com.fan.admin.service.CourseService;
import com.fan.admin.service.StudentScoresService;
import com.fan.commons.pojo.Course;
import com.fan.commons.pojo.StudentScores;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author fan
 * @date 2021/3/11
 */
@Service
public class StudentScoresMapperImpl implements StudentScoresService {

	@Autowired
	private StudentScoresMapper studentScoresMapper;

	@Autowired
	private CourseService courseService;

	@Override
	public int deleteByPrimaryKey(Integer id) {
		return 0;
	}

	@Override
	public int insert(StudentScores record) {
		return 0;
	}

	@Override
	public int insertSelective(StudentScores record) {
		return 0;
	}

	@Override
	public StudentScores selectByPrimaryKey(Integer id) {
		return studentScoresMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(StudentScores studentScores) {
		Course course = courseService.queryCourseByCourseId(studentScores.getCourseId());
		int attendance = course.getAttendance();
		int classPerformance = course.getClassPerformance();
		int task = course.getTask();
		int experiment = course.getExperiment();
		int exam = course.getExam();
		double sum = attendance + classPerformance + experiment + task + exam;
		double score = studentScores.getAttendance() * (attendance / sum) + studentScores.getClassPerformance() * (classPerformance / sum)
				+ studentScores.getExperiment() * (experiment / sum) + studentScores.getTask() * (task / sum) + studentScores.getExam() * (exam / sum);
		studentScores.setScore(score);
		studentScores.setNewVersion(System.currentTimeMillis() + "");
		return studentScoresMapper.updateByPrimaryKeySelective(studentScores);
	}

	@Override
	public int updateByPrimaryKey(StudentScores record) {
		return 0;
	}

	@Override
	public List<StudentScores> queryTemp() {
		return null;
	}

	@Override
	public List<StudentScores> selectByCourseId(String courseId) {
		return studentScoresMapper.selectByCourseId(courseId);
	}
}
